package io.gitee.yth.design.pattern.test.core.pattern.creational.factory.pizzaorderservice;

import io.gitee.yth.design.pattern.test.core.pattern.creational.factory.pizza.Pizza;
import io.gitee.yth.design.pattern.test.core.pattern.creational.factory.pizzafactory.PizzaSimpleFactory;

/**
 * 使用简单工厂
 *
 * @author yth
 * @since 2023-04-16-23:39
 */
public class PizzaOrderServiceImpl2 implements IPizzaOrderService {

    private PizzaSimpleFactory pizzaFactory = new PizzaSimpleFactory();

    public void setPizzaFactory(PizzaSimpleFactory factory) {
        pizzaFactory = factory;
    }

    @Override
    public Pizza orderPizza(String orderType) {
        Pizza pizza = pizzaFactory.createPizza(orderType);
        if (pizza == null) return null;
        pizza.prepare();
        pizza.bake();
        pizza.cut();
        pizza.box();
        return pizza;
    }

}
